package com.uroad.jilinpda.presenter;

import android.app.Activity;
import android.text.TextUtils;

import com.uroad.jilinpda.activity.LoginActivity;
import com.uroad.jilinpda.activity.MainActivity;
import com.uroad.jilinpda.layer.LoginLayer;
import com.uroad.jilinpda.layer.MainLayer;
import com.uroad.jilinpda.modle.CheckVersionMDL;

public class MainPresenter extends BaseMvpPresenter<MainActivity>{

    private MainLayer layer;
    MainActivity view;

    public MainPresenter(Activity activity){
        this.layer = new MainLayer(activity, new MainCallBack());
    }

    public void checkAttach(){
        view = checkViewAttach();
    }

    public boolean isOnLine(){
       return layer.isOnLine();
    }

    public void getVersionInfo(){
        layer.getVersionInfo();
    }

    public void downLoad(String url){
        layer.downLoad(url);
    }

    public void logout(){
        layer.logout();
    }

    private class MainCallBack implements MainLayer.MainLayerCallBack {

        @Override
        public void appVersionCallBack(CheckVersionMDL mdl) {
            view.showDownloadDialog(mdl);
        }

        @Override
        public void loginOutCallBack() {
            view.showToast("退出登录成功");
            view.logout();
        }

        @Override
        public void downLoadCallBack(long progress, int code) {
            if (code == 1&&progress != -1)
                view.tripDialogContent(progress);
            else if(code == 0){
                view.tripDialogDissmis();
            }
        }

        @Override
        public void onSuccess() {

        }

        @Override
        public void onFailure(String fail) {
            view.showToast(fail);
        }
    }

}
